/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modules.enderecamento.gui.custom;

import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.PlainDocument;

/**
 *
 * @author Clezio
 */
public class WMSJTextField extends JTextField {

    public WMSJTextField(int maxLength) {
        super(maxLength);
    }

    public WMSJTextField() {
        super(1);
    }

    protected Document createDefaultModel() {
        return (Document) new UpperCaseDocument();
    }

    static class UpperCaseDocument extends PlainDocument {

        public void insertString(int offs, String str, AttributeSet a)
                throws BadLocationException {

            if (str == null) {
                return;
            }
            char[] upper = str.toCharArray();
            for (int i = 0; i < upper.length; i++) {
                upper[i] = Character.toUpperCase(upper[i]);
            }
            super.insertString(offs, new String(upper), a);
        }
    }
}
